package com.wq.httpclientcore.enums;

public enum DatabaseType {
    MYSQL("mysql", "com.mysql.cj.jdbc.Driver", "jdbc:mysql://%s:%d/%s"),
    POSTGRESQL("postgresql", "org.postgresql.Driver", "jdbc:postgresql://%s:%d/%s");

    private final String typeName;
    private final String driverClass;
    private final String jdbcUrlTemplate;

    DatabaseType(String typeName, String driverClass, String jdbcUrlTemplate) {
        this.typeName = typeName;
        this.driverClass = driverClass;
        this.jdbcUrlTemplate = jdbcUrlTemplate;
    }

    public static DatabaseType from(String typeName) {
        for (DatabaseType type : values()) {
            if (type.typeName.equalsIgnoreCase(typeName)) {
                return type;
            }
        }
        throw new IllegalArgumentException("不支持的数据库类型: " + typeName);
    }

    public String getTypeName() {
        return typeName;
    }

    public String getDriverClass() {
        return driverClass;
    }

    public String getJdbcUrlTemplate() {
        return jdbcUrlTemplate;
    }
}